package com.itheima.game;

import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class PokerSortOne {
    //扑克第一种排序方式

    //思路：
    //先利用HasMap 与 数字1-54 产生一一对应关系
    static HashMap<Integer, String> hm = new HashMap<>();//数字与扑克对应集合
    static ArrayList<Integer> list = new ArrayList<>(); //数字序号集合

    //♦3 ♦4 ♦5 ♦6 ♦7 ♦8 ♦9 ♦10 ♦J  ♦Q  ♦K  ♦A  ♦2
    //1  2  3  4  5  6  7  8   9   10  11  12  13
    //♦3 ♦4 ♦5  ♦7 ♦J
    //40 41 42 44 48
    static {
        //牌的颜色
        String[] colors = {"♥", "♠", "♣", "♦"};
        //牌的数字
        String[] numbers = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};


        //创建变量记录牌的序号
        int pokerNum = 1;
        for (String n : numbers) {
            for (String c : colors) {
                list.add(pokerNum);
                hm.put(pokerNum, c + n);
                pokerNum++;
            }
        }


        //添加大小王
        list.add(pokerNum);
        hm.put(pokerNum, "大王");
        pokerNum++;
        list.add(pokerNum);
        hm.put(pokerNum, "小王");

//        System.out.println(list);
//        System.out.println(hm);

    }

    //空参构造
    public PokerSortOne() {
        //洗牌
        Collections.shuffle(list);
        //发牌  创建三个玩家及底牌的集合
        TreeSet<Integer> lord = new TreeSet<>();//TreeSe集合 可以默认从小到大排序
        TreeSet<Integer> player1 = new TreeSet<>();
        TreeSet<Integer> player2 = new TreeSet<>();
        TreeSet<Integer> player3 = new TreeSet<>();

        for (int i = 0; i < list.size(); i++) {
            int pokerNum = list.get(i);
            if (i <= 2) {
                lord.add(pokerNum);
            } else if (i % 3 == 1) {
                player1.add(pokerNum);
            } else if (i % 3 == 2) {
                player2.add(pokerNum);
            } else {
                player3.add(pokerNum);
            }
        }

        //看牌
        lockPoker("底牌", lord);
        lockPoker("玩家1", player1);
        lockPoker("玩家2", player2);
        lockPoker("玩家3", player3);

    }

    /**
     * @param list 玩家的派克
     * @param name 玩家名称
     */
    public static void lockPoker(String name, TreeSet<Integer> list) {
        System.out.print(name + ": ");
        for (Integer s : list) {
            String poker = hm.get(s);//使用list的值 去hm集合中找到对应的牌
            System.out.print(poker + " ");
        }
        System.out.println();
    }


}
